﻿using System;
using System.Windows.Data;
using System.Windows;

namespace Dsl.Ped.Common.Converters
{
    /// <summary>
    /// Converter of a bool to <see cref="Visibility"/>
    /// </summary>
    public class BoolToVisibilityConverter : IValueConverter
    {
        #region Implementation of IValueConverter

        /// <summary>
        /// Converts a bool value to <see cref="Visibility"/>.
        /// True => <see cref="Visibility.Visible"/>; False => <see cref="Visibility.Hidden"/> or <see cref="Visibility.Collapsed"/> (if the convert parameter is specified, returns <see cref="Visibility.Collapsed"/>)
        /// </summary>
        /// <param name="value">Boolean value to be converted</param>
        /// <param name="targetType">Target type of a conversion</param>
        /// <param name="parameter">Conversion parameter</param>
        /// <param name="culture">Culture under which the conversion is done. Doesn't affect the conversion at all</param>
        /// <returns>Boolean value converted to <see cref="Visibility"/></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool valueStrong = (bool)value;

            var requestedTypeWhenParameter = Visibility.Hidden;
            if (parameter != null)
            {
                requestedTypeWhenParameter = Visibility.Collapsed;
            }

            if (valueStrong) return Visibility.Visible;
            else return requestedTypeWhenParameter;
        }

        /// <summary>
        /// Backwards conversion is not implemented
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
